package me.mononin.common.factory.presenter;

public class BasePresenter<T extends BaseContract.View> implements BaseContract.Presenter {

    private T mView;

    public BasePresenter(T view){
        setView(view);
    }

    protected void setView(T view){
        this.mView = view;
        this.mView.setPresenter(this);
    }

    /**
     * 给子类调用View
     * 但不允许子类复写
     * @return
     */
    protected final T getView(){
        return mView;
    }

    /**
     * 开始的时候进行Loading调用
     */
    @Override
    public void start() {
        T view = mView;
        if (view!=null){
            view.showLoading();
        }
    }

    @Override
    public void destroy() {
        T view = mView;
        mView = null;
        if (view!=null){
            view.setPresenter(null);
        }
    }
}
